package com.zlq.login.ajax;

import com.zlq.login.dao.UserDaoLo;
import com.zlq.login.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/searchAjax")
public class SearchAjax extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=Utf-8");

        String str = req.getParameter("str");

        List<User> us = new UserDaoLo().selectByLike("%"+str+"%");
        req.getSession().setAttribute("us", us );
//        req.getRequestDispatcher("/static/search.jsp").forward(req,resp);
        resp.sendRedirect("/static/search.jsp");


//        List users = null;
//        try {
//            users = new UserDaoLo().selectAll();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println(users);
//        req.getSession().setAttribute("users", users );
//        resp.sendRedirect("/static/listUser.jsp");
    }
}
